<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Event</title>
</head>

<body>
  <div id="ev">
    <style>
      #ev {
        width: 300px;
        height: 100px;
        background-color: red;
        color: #fff;
        text-align: center;
        line-height: 100px;
      }
    </style>
    目标元素
  </div>
  <script>
    var ev = document.getElementById('ev');

    window.addEventListener('click', function () {
      console.log('window captrue')
    }, true)

    document.addEventListener('click', function () {
      console.log('document capture')
    }, true)

    document.documentElement.addEventListener('click', function() {
      console.log('html capture')
    }, true)

    document.body.addEventListener('click', function() {
      console.log('body capture')
    }, true)

    ev.addEventListener('click', function() {
      console.log('ev capture')
    }, true)

    var testEvent = new Event('test');
    ev.addEventListener('test', function () {
      console.log('test dispatch')
    })
    setTimeout(() => {
      ev.dispatchEvent(testEvent)
    }, 1000);

    var testCustom = new CustomEvent('testCustom');
    ev.addEventListener('testCustom', function (e) {
      console.log('testCustom dispatch', e)
    })
    setTimeout(() => {
      ev.dispatchEvent(testCustom)
    }, 1000);


  </script>
</body>

</html>
